import unittest

from framework.AW.STrak import strak
from framework.AW.STrak.process import *
from framework.AW.STrak.strak import *
from framework.AW.STrak.station import *
from framework.AW.STrak.car import *


# 最大工位回退距离
def maximum_back_distance_of_station():
    try:
        """

        """
        initial()
        Set_max_back_dis_of_station(80.0)
        assert (car_pos(1) - 250) < 1, "[小车位置错误]"
        restart()
        assert abs(Read_sation_pos(1) - Read_car_goal_pos(1)) < 0.01, "[小车目标位置不正确]"

    except Exception as e:
        print(f"测试过程出现异常:{e}")
        raise
    finally:
        Set_max_back_dis_of_station(0.01)


class MaximumBackDistanceOfStation(unittest.TestCase):
    @staticmethod
    def testOn():
        maximum_back_distance_of_station()


# 最大工位回退距离为负
def back_distance_negative():
    try:
        """

        """
        initial()
        Set_max_back_dis_of_station(-1.0)
        restart()
        # 目标位置不能是工位1
        assert abs(Read_sation_pos(1) - Read_car_goal_pos(1)) > 1, "[小车目标位置不正确]"

    except Exception as e:
        print(f"测试过程出现异常:{e}")
        raise
    finally:
        Set_max_back_dis_of_station(0.01)


class MaximumBackDistanceOfStationNegative(unittest.TestCase):
    @staticmethod
    def testOn():
        back_distance_negative()


# 最大工位回退距离为0 小于0.001
def back_distance_zero():
    try:
        """
        """
        initial()
        Set_max_back_dis_of_station(0.0)
        restart()
        # 目标位置不能是工位1
        assert abs(Read_sation_pos(1) - Read_car_goal_pos(1)) > 1, "[小车目标位置不正确]"

        Set_max_back_dis_of_station(0.0001)
        restart()
        # 目标位置不能是工位1
        assert abs(Read_sation_pos(1) - Read_car_goal_pos(1)) > 1, "[小车目标位置不正确]"

        Set_max_back_dis_of_station(80)
        restart()
        # 目标位置是工位1
        assert abs(Read_sation_pos(1) - Read_car_goal_pos(1)) < 0.01, "[小车目标位置不正确]"
    except Exception as e:
        print(f"测试过程出现异常:{e}")
        raise
    finally:
        Set_max_back_dis_of_station(0.01)


class MaximumBackDistanceOfStationZero(unittest.TestCase):
    @staticmethod
    def testOn():
        back_distance_zero()


# 最大工位回退距离为0 小于0.001
def back_distance_cross_zero():
    try:
        """
        """
        modify_station_pos(1, 2800.0)
        initial()
        Set_max_back_dis_of_station(500.0)
        restart()
        # 目标位置是工位1
        assert abs(Read_sation_pos(1) - Read_car_goal_pos(1)) < 0.01, "[小车目标位置不正确]"
    except Exception as e:
        print(f"测试过程出现异常:{e}")
        raise
    finally:
        Set_max_back_dis_of_station(0.01)
        modify_station_pos(1, 200.25)


class MaximumBackDistanceOfStationCrossZero(unittest.TestCase):
    @staticmethod
    def testOn():
        back_distance_cross_zero()
